export const throttle = (fn: Function, wait: number) => {
    let previous : Date | number = 0;//定义变量记录上一次执行时间
    let time : any;
    return function (this: any) {
      let args = arguments;
      let now = new Date()
      let interval:number = wait - (Number(now) - Number(previous))
      if(interval <= 0){
          clearTimeout(time)
          time = undefined
          fn.apply(this, args);
          previous = new Date()
      }else if(!time){
          time = setTimeout(()=>{
              clearTimeout(time)
              time = undefined
              fn.apply(this, args);
              previous = new Date()
          },interval)
      }
    }
}
  
export default throttle;